package com.yxc.live_it.activity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;

import com.xuexiang.xui.widget.actionbar.TitleBar;
import com.xuexiang.xui.widget.button.SmoothCheckBox;
import com.xuexiang.xui.widget.edittext.MultiLineEditText;
import com.xuexiang.xui.widget.imageview.RadiusImageView;
import com.yxc.live_it.R;

public class LiveEnterActivity extends BaseActivity  implements OnClickListener {

    private TitleBar titleBar;

    private SmoothCheckBox inviteBtn,anyBtn;

    private LinearLayout anyLayout,inviteLayout,liveVistorLayout;

    private MultiLineEditText vistors;

    private RadiusImageView openRecord;

    private boolean isOpenRecord = true;

    private Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch(msg.what){
                case 0:
                    anyBtn.setChecked(true,true);
                    inviteBtn.setChecked(false);
                    liveVistorLayout.setVisibility(View.GONE);
                    vistors.setContentText("");
                    break;
                case 1:
                    inviteBtn.setChecked(true,true);
                    anyBtn.setChecked(false);
                    liveVistorLayout.setVisibility(View.VISIBLE);
                    break;
                case 2:
                    isOpenRecord = !isOpenRecord;
                    if(isOpenRecord){
                        openRecord.setImageDrawable(getResources().getDrawable(R.mipmap.open_icon));
                    }else{
                        openRecord.setImageDrawable(getResources().getDrawable(R.mipmap.close_icon));
                    }
                    break;

            }
        };
    };



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.live_enter_main);
        initView();
        initOnClick();
        //隐藏虚拟导航栏
        if(hasNavBar(this)){
            hideBottomUIMenu();
        }

    }

    private void initView() {
        titleBar = findViewById(R.id.title_bar);
        titleBar.setTitle("立即直播");
        inviteBtn = findViewById(R.id.invite_btn);
        anyBtn = findViewById(R.id.any_btn);
        anyLayout = findViewById(R.id.any_layout);
        inviteLayout = findViewById(R.id.invite_layout);
        liveVistorLayout = findViewById(R.id.live_vistor_layout);
        vistors = findViewById(R.id.live_vistor_txt);
        openRecord = findViewById(R.id.open_record);
        inviteBtn.setChecked(true);
    }

    private void initOnClick(){
        anyLayout.setOnClickListener(this);
        inviteLayout.setOnClickListener(this);
        anyBtn.setOnClickListener(this);
        inviteBtn.setOnClickListener(this);
        openRecord.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Message msg = new Message();
        switch (v.getId()){
            case R.id.any_layout:
                msg.what = 0;
                break;
            case R.id.invite_layout:
                msg.what = 1;
                break;
            case R.id.any_btn:
                msg.what = 0;
                break;
            case R.id.invite_btn:
                msg.what =1 ;
                break;
            case R.id.open_record:
                msg.what =2 ;
                break;
        }
        mHandler.handleMessage(msg);
    }
}
